package sistema.web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import sistema.web.dtos.PersonaDTO;

/**
 * Servlet implementation class CerrarSesion_Servlet
 */
@WebServlet("/CerrarSesion_Servlet")
public class CerrarSesion_Servlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CerrarSesion_Servlet() {
        super();
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		
		HttpSession session = request.getSession(false);		
		PersonaDTO dtoPersona = (PersonaDTO) session.getAttribute("username");
		
		if(dtoPersona != null) {
			session.removeAttribute("username");
			session.invalidate();
			response.sendRedirect("index.jsp");
		}
	}
}